package com.collection;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * 使用Perperties输出到文件
 *
 * 1. .properties
 *  store(outputStream out,String comments)
 *  store(writer writer,String comments)
 *  2. .xml
 *  storeTOXML(OutputStream os,String comment);默认utf-8
 *  storeTOXML(OutputStream os,String comment,String encoding)
 * @author jiangbang
 * @date 2016/5/31
 */
public class Perperties2 {

    public static void main(String[] args) throws IOException {
        //创建对象
        Properties pro = new Properties();
        //存储
        pro.setProperty("driver","oracle.jdbc.driver.OracleDriver");
        pro.setProperty("url","jdbc:oracle:thin:@localhost:1521:orcl");
        pro.setProperty("user","root");
        pro.setProperty("pwd","123456");

        //存储到e:other 绝对路径   盘符：/
        pro.store(new FileOutputStream(new File("e:/db.properties")),"db配置");
        pro.storeToXML(new FileOutputStream(new File("e:/db.xml")),"db配置");
        //使用相对路径  当前工程
        pro.store(new FileOutputStream(new File("db.properties")),"db配置");  //当前路径
        pro.store(new FileOutputStream(new File("src/db.properties")),"db配置");  //src下路径

    }
}
